package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.tumor.ReportRecord;
import com.ruoyi.system.service.tumor.IReportRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报告记录Controller
 *
 * @author ruoyi
 * @date 2023-09-09
 */
@RestController
@RequestMapping("/system/record")
public class ReportRecordController extends BaseController
{
    @Autowired
    private IReportRecordService reportRecordService;

    /**
     * 查询报告记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReportRecord reportRecord)
    {
        startPage();
        List<ReportRecord> list = reportRecordService.selectReportRecordList(reportRecord);
        return getDataTable(list);
    }

    /**
     * 导出报告记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "报告记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReportRecord reportRecord)
    {
        List<ReportRecord> list = reportRecordService.selectReportRecordList(reportRecord);
        ExcelUtil<ReportRecord> util = new ExcelUtil<ReportRecord>(ReportRecord.class);
        util.exportExcel(response, list, "报告记录数据");
    }

    /**
     * 获取报告记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(reportRecordService.selectReportRecordById(id));
    }

    /**
     * 新增报告记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "报告记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportRecord reportRecord)
    {
        return toAjax(reportRecordService.insertReportRecord(reportRecord));
    }

    /**
     * 修改报告记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "报告记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportRecord reportRecord)
    {
        return toAjax(reportRecordService.updateReportRecord(reportRecord));
    }

    /**
     * 删除报告记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "报告记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reportRecordService.deleteReportRecordByIds(ids));
    }

    /**
     * 修改报告记录
     */
    @PutMapping(value = "/changeInterpretReport")
    public AjaxResult changeInterpretReport(@RequestBody ReportRecord reportRecord)
    {
        return toAjax(reportRecordService.changeInterpretReport(reportRecord.getId(),reportRecord.getIsInterpret()));
    }

}
